package com.atguigu.mr.table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @description: xxx
 * @time: 20200102 11:07
 * @author: baojinlong
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TableBean implements Writable {
    /**
     * 订单id
     */
    private String id;
    /**
     * 产品id
     */
    private String pid;
    /**
     * 产品数量
     */
    private Integer amount;
    /**
     * 产品名称
     */
    private String pName;
    /**
     * 标记是订单表还是产品表
     */
    private String flag;

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(id);
        out.writeUTF(pid);
        out.writeInt(amount);
        out.writeUTF(pName);
        out.writeUTF(flag);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        // 顺序要一致
        id = in.readUTF();
        pid = in.readUTF();
        amount = in.readInt();
        pName = in.readUTF();
        flag = in.readUTF();
    }

    @Override
    public String toString() {
        return "TableBean{" +
                "id='" + id + '\'' +
                ", amount=" + amount +
                ", pName='" + pName + '\'' +
                '}';
    }
}
